<?php
// include classes
session_start();
require_once '../Model/M_Validation.php';
require_once '../Model/M_login.php';
// initialize classes
$validation = new Com_Validation();
$login = new Com_Login();
// obtain username and password from login view
$username = $_POST['username'];
$password = $_POST['password'];
// validate username and password 
$isUsername = $validation->isUsername($username);
$isPassword = $validation->isPassword($password);
// if username and password validation is correct
if($isUsername == true && $isPassword == true){
    // check username and password in DB
    $credential = $login->check_credential($username, $password);
    // if username and password are recorded in DB
    if($credential == true){
        $_SESSION['username'] = $username;
        $_SESSION['correctCredential']=true;
        header('Location:../View/Home.php');
    }
    else{
        $_SESSION['incorrectCredential']=true;
        header('Location:../View/Login.php');
    }
}
 else {
     $_SESSION['incorrectCredential']=true;
     header('Location:../View/Login.php');
}
?>
